package io2.nio;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

/**
 * 视图缓冲器
 */
public class ViewBufferDemo {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        IntBuffer intBuffer = buffer.asIntBuffer();
        intBuffer.put(1024);
        intBuffer.flip();
        System.out.println("intBuffer.get => " + intBuffer.get());
        buffer.rewind();
        System.out.println("buffer.get => " + buffer.get());
        System.out.println("buffer.get => " + buffer.get());
        System.out.println("buffer.get => " + buffer.get());
        System.out.println("buffer.get => " + buffer.get());

        System.out.println("buffer.clear");
        intBuffer.clear();
        intBuffer.put(16843009);
        buffer.flip();
        System.out.println("buffer.get => " + buffer.get());
        System.out.println("buffer.get => " + buffer.get());
        System.out.println("buffer.get => " + buffer.get());
        System.out.println("buffer.get => " + buffer.get());
    }
}
